var uploadObject = {
    swf: '/plugin/webuploader/Uploader.swf', //swf文件路径
    defaultOption: {//默认初始化值
        auto: true,//选完文件后，是否自动上传
        pick: {},//选择文件的按钮  {Selector, Object}
        server: '/api/upload/index',//接收文件服务器端
        fileVal: 'upfile',//[可选] [默认值：'file'] 设置文件上传域的name
        formData: {"category": "image"},
        fileSingleSizeLimit: 200 * 1024 * 1024,
        resize:false,// 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
        accept: {//只允许选择图片文件。
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
        },
        func: {
        },
        duplicate: true,//根据文件名字、文件大小和最后修改时间来生成hash Key.
        onError: function (type) {
            if (typeof layer === "undefined") {
                func = alert;
            } else
            {
                func = layer;
            }
            switch (type)
            {
                case 'F_EXCEED_SIZE'://文件大小超出限制
                    func('文件太大了!!换个小的再试吧!');
                    break;
                case 'Q_TYPE_DENIED'://文件类型不正确
                    func('文件类型不正确!!!');
                    break;
                case 'Q_EXCEED_NUM_LIMIT'://文件数量fileNumLimit
                    func('文件数量超限');
                    break;
                case 'Q_EXCEED_SIZE_LIMIT'://文件总大小
                    func('文件总大小超限');
                    break;
                default:
                    func(type);
            }
        }
    },
    init: function (option) {
        if (typeof option.pick === "undefined")
        {
            alert('upload docment element is undefined');
        }

        webuploaderOptions = {};
        var keys = [
            "auto", "pick", "server", "fileVal", "formData", "accept", "duplicate", "fileSingleSizeLimit", 'compress'
        ];
        var k;
        for (var i in keys) {
            k = keys[i];
            webuploaderOptions[k] = typeof option[k] === "undefined" ? this.defaultOption[k] : option[k];
        }
        var uploader = WebUploader.create(webuploaderOptions);

        for (var key in option.func) {
            fu = option.func[key];
            if(typeof fu === "function"){
                uploader.on(key, fu);
            }
        }

        /*if (typeof option.uploadComplete == 'function')
         {
         // 文件上传成功，给item添加成功class, 用样式标记上传成功。
         uploader.on('uploadComplete', function (file) {
         option.uploadComplete(file);
         });
         }
         if (typeof option.uploadSuccess == 'function')
         {
         uploader.on('uploadSuccess', function (file, response) {
         option.uploadSuccess(file, response);
         });
         }
         if (typeof option.uploadProgress == 'function')
         {
         uploader.on('uploadProgress', function (file, percentage) {
         option.uploadProgress(file, percentage);
         });
         }*/
        if (typeof option.onError === "undefined")
        {
            option.onError = this.defaultOption.onError;
        }
        console.log(option);
        uploader.on('error', function (type) {
            option.onError(type);
        });
        return uploader;
    }
};